package com.qf.flash.ui.mine;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.R;
import com.qf.flash.adapter.HeadFrameAdapter;
import com.qf.flash.model.PhotoLinesBean;
import com.qf.flash.mvp.contract.MyPhoneLinesContract;
import com.qf.flash.mvp.presenter.MyPhotoLinesPresent;
import com.qf.flash.widget.GridSpaceItemDecoration;
import com.qf.flashlib.app.FlashLib;
import com.qf.flashlib.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ChooseHeadFrameActivity extends BaseActivity implements MyPhoneLinesContract.View {
    @BindView(R.id.tv_top_back)
    TextView tvTopBack;
    @BindView(R.id.tv_top_title)
    TextView tvTopTitle;
    @BindView(R.id.rv_frame)
    RecyclerView rvFrame;
    private HeadFrameAdapter headFrameAdapter;
    private MyPhotoLinesPresent photoLinesPresent;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_choose_frame;
    }

    @Override
    protected void initViewAndData() {
        tvTopTitle.setText("选择头像框");
        initRvData();
    }

    private void initRvData() {
        rvFrame.setLayoutManager(new GridLayoutManager(ChooseHeadFrameActivity.this, 3));
        headFrameAdapter = new HeadFrameAdapter(this,new ArrayList<>());
        rvFrame.setAdapter(headFrameAdapter);
        //设置分隔线
        GridSpaceItemDecoration decoration = new GridSpaceItemDecoration(3, (int) (FlashLib.density * 10), true);
        rvFrame.addItemDecoration(decoration);
        photoLinesPresent.getPhotoLines(UserMgr.getInstance().getLoginUser().getUid());
    }

    @OnClick(R.id.tv_top_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void setUi(List<PhotoLinesBean> photoLinesBeans) {
        headFrameAdapter.setDatas(photoLinesBeans);
    }


    @Override
    protected void initInject() {
        super.initInject();
        photoLinesPresent = new MyPhotoLinesPresent();
        initPresenters(photoLinesPresent);
    }
}
